using System.Linq.Expressions;
using Zhaoxi.Zhihu.SharedKerel.Domain;

namespace Zhaoxi.Zhihu.SharedKerel.Specification;

public abstract class Specification<T>: ISpecification<T>where T :class,IEntity<int>
{
    public Expression<Func<T, bool>>? FilterCondition { get; protected set; }
    public List<Expression<Func<T, object>>> Includes { get; } = new();
    public List<string> IncludeStrings { get; } = new();
    public Expression<Func<T, object>> OrderBy { get;private set; }
    public Expression<Func<T, object>> OrderByDescending { get;private set; }
    public Expression<Func<T, object>> GroupBy { get;private set; }
    public int Take { get;private set; }
    public int Skip { get; private set; }
    public bool IsPagingEnabled { get; private set; }

    protected void AddInclude(Expression<Func<T, object>> includeExpression)
    {
        Includes.Add(includeExpression);
    }

    protected void AddInclude(string includeString)
    {
        IncludeStrings.Add(includeString);
    }

    protected void SetPaging(int skip, int take)
    {
        Skip = skip;
        Take = take;
        IsPagingEnabled = true;
    }

    protected void SetOrderBy(Expression<Func<T, object>> orderByExpression)
    {
        OrderBy = orderByExpression;
    }

    protected void SetOrderByDescending(Expression<Func<T, object>> orderByExpression)
    {
        OrderByDescending= orderByExpression;
    }

    protected void SetGroupBy(Expression<Func<T, object>> groupByExpression)
    {
        GroupBy = groupByExpression;
    }
}